package TankGame;

import javax.swing.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;
import java.util.Scanner;

/**
 * @author 王艺锡
 * @version 1.0
 */
@SuppressWarnings({"all"})
public class TankGame03 extends JFrame {
    //定义Panel
    MyPanel mp = null;
    static Scanner scanner = new Scanner(System.in);
    public static void main(String[] args) {
        TankGame03 tankGame03 = new TankGame03();
    }

    public TankGame03(){
        System.out.println("==================");
        System.out.println("1.新游戏   2.继续游戏");
        System.out.println("==================");
        System.out.print("请选择:>");
        String Key = scanner.next();
        mp = new MyPanel(Key);
        Thread thread = new Thread(mp);
        thread.isDaemon();
        //启动MyPanel线程，重绘面板
        thread.start();
        this.add(mp);
        this.setSize(1300,750);
        this.addKeyListener(mp);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setVisible(true);

        //在 JFrame 中增加响应关闭窗口的处理
        this.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                try {
                    Recorder.keepRecord();
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
                System.exit(0);
            }
        });
    }
}
